package spark.so

import java.util

import com.inf.featureCompare.FeatureCompare
import com.sun.jersey.core.util.Base64
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
/**
  * Created by zhangbn on 2018/10/10.
  */
object SoCompTest {
  def main(args: Array[String]): Unit = {
    System.setProperty("hadoop.home.dir", "E:\\hadoop-common-2.7.3-bin-master")
    System.setProperty("HADOOP_USER_NAME", "admin")

    val sparkConf = new SparkConf()
      .setAppName("SoComp")
      .setMaster("local[3]")

    val spark = SparkSession
      .builder()
      .config(sparkConf)
      .enableHiveSupport()
      .getOrCreate()

    //    spark.sqlContext.sql("use ods")

    val arr = Array("7qpXQideAAAAAQAAo0jYvNqN5TzrRs88iUUgPpQl/rwCbSC9HrC4vM8mQ72j5tG6/Hh8vCf+0T3PurW84OjwvIlqdL0Se0e7d5bsvIABGT3a18C9D5yEvYOfWb2MWBk9WnE5Pb3nkD2o37C9KImNPfS3BL2bL+Q9US+pPS+D5zxSBmu7lGv3vRs1GDv8HI68t0YivemJtD0WgAy9xvHAvQ398T3M27y7uO+HPc+/ozt3qXg8og7XO/6j3bv3boi9lYQSPWObhz3C2o88nrTMvTaf/D0g6449uVGSvVpyfDvHlTU9SkOaPIqO6bvM79o8tmCOPVkABrwB+ak8y4INPm3xEL3O+nS9lYk8vQO3L70ZR0O9hhyGPRu8R70YvvM83RTLvA273Txkdhw9Dy82PG76Ub2ieMQ9P6F3PbbbGT0500Y8uHUbOjjv2byk79K8wvYZPDji3bwTUHI8+hhyO/7oiz32BJk905HwOY/UIL6FRrQ8APTGPUmuHD4QXMC8aj7UPUleib0F5vw8hlVguqS0Cb1Kuyc952ocPSg9PTxRUH29YvoWPo10Cj3ROcI8Oj3bPUsOCLyT91+9xh2kvefk3z0TJwu9j5JsPcU4Er7EQP+91wOAvsQQKjzVPp48uHKLvQoPyT3Wngg8GmNiPUOuTb0zLLW9H2FAPX3bjr2oJhC+2UC/vQsPSL0pe7w8C03VPQfRg70Z+Ow9lN0/vD4UurvL9yg9St9Wv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sb1eBn+9AipQO79nUTyH45a9pELNPMfNKz2vxQI+6khpvVJvg73L3mg9ydMpPRQ1p72/V0I9HW2rvVJl3TzCG648z1XwPA79wjxy9f89MpdcvV/5rjziSU48kBHlPToG/D2mgVC9PlWNu5yyhj1aBi89b2iFvca6O72aBZo9T90HvdfOWz228IY8mUlwPcNdN7ze0Ms9OeQiPQwvl70azEM9oGcOvicXkj2PP/+8uqfmvI3pNb23peg8cgQFvQ3oHT3KjhO96z7xPQd8Kz2C7xw8IOnHvd7RVj37ehI8uEUKvTsxhTyooSC9XGQbvQQljb1r5AG8+0sLO9tGd7p16Kc8hijdPT780LzX/e+96QZrPRxdzjynmNq8+cuAPRw2+rxYY6c8VQN8vUknDLwrXQO9YKttPb74e7ydSp28fip6vQjfEL3edyc8btCCvGOfoj2QukO9fsMqve3BNrxThwY95mkKvNgHj7zJoeM7WsuGveYarr3XE8Y9e15XO4Ht6L0zO8s65D4/usJaIL51zq48mEZWOzx/tj1V9+G9v7u+PXszoT0Db3i93cTAPf/dMbyXx/u8NQQ9O9h2GbyyaLg9iaCFPNoIYDz0FO48tR79O+ZVnL1G8qu9AXU6vQdZY7339xW+zb4jvaTkIj2oyJQ9p/pzvUy5xLxvinI91R6PvfrDx70395w9JpcrvdUzyD3cGc89QMcpPlS/er1XI7I8GZBsOpuTObshcUC9g1+UPbBhdj1MZ6W953hqPQ==")
    val rdd = spark.sparkContext.parallelize(arr)

    //    val rowRDD = rdd.map(Row(_))
    //    val schema = StructType(Seq(StructField("feature", StringType, true)))
    //
    //    val rdd2DF = spark.createDataFrame(rowRDD, schema)
    //
    //    val joinRDD = rdd2DF.crossJoin(rdd2DF)
    //    joinRDD.show(50)

    //    val f = new FeatureCompare();
    //rdd.foreach(x=>{
    //  f.featureCompByByte(x, list)
    //})
    //    val doubleArrays = new FeatureCompare().featureCompByByte(var1, list)


    //    val feaTure1 = "7qpXQideAAAAAQAAMmHpOi1BbjpY6YM9NtXDPIFAobwM3c88amnCPRxbNT35GY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TCQvKoB/LxzX1g9OiRivcEJzz2+tiU8jtksPnU/DjwPgDy9kmE2PCFIcz2oaYA9U7SuPXUJh7xEvto9KItvvUn+/jwwK7G9tTkKPq31nbwtXNS9cr8bPeQ0zLtjLNq6s8qavUDgiDzcdqy904aivSUQaT00vIi8Sr5bPfevFr0TS/G84JyhPZANwzyJWOQ90TjbvSKlaD13Llm9daIUvXO3Yb3PIpi8BugIPgckW72fCLc9oqTQvaIKMTu+cIQ9ucHOvAT2tzxHKvk8W0BIPZogQjzP66K9zwTQvO5pvLvF+Wo9AEMOvdbJ9T20D5S8lkbOvStlrT3bfDU9NF3DOzJoRD1V4yM8PP3ZPZuHlz026cM9QSrIvaabgb0eOZW92GMUvmyuizvOmTK99E+TvPe8Uj3LsuI7BleZPLVBM73KVF89LCxGPV6wLD1qPLs9dI/+PZmpLbvRTXW74tKOPS/exDxavv48+lE7PEahmr1/GdM8yer9O2S72b1i8+g8s54gvAJ9Bb3D0eg8HapLvQ=="


    val list = new util.ArrayList[Array[Byte]]
    //    val var1 = Base64.decode(feaTure1)

    for (i <- 0 until arr.length) {
      val var2 = Base64.decode(arr(i))
      list.add(var2)
    }


    val rstArrRdd = rdd.map(x => {
      val var1 = Base64.decode(x)
      new FeatureCompare().featureCompByByte(var1, list)
    })

    //    val doubleArrays = new FeatureCompare().featureCompByByte(var1, list)
    //    val doubleArrays = featureCompByByte(var1, list)
    rstArrRdd.saveAsTextFile("/home/zhangbn/")


    println("rstArrRdd.partitions.length=" + rstArrRdd.partitions.length)
    //    for (i <- 0 until doubleArrays.length) {
    //      println(doubleArrays(i))
    //    }


  }

  def featureCompByByte(var1: Array[Byte], var2: util.ArrayList[Array[Byte]]): Array[Double] = {

    Array(0.25, 0.56)
  }
}
